package io.renren.modules.hos.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.hos.vo.CollMedicineContentVo;
import io.renren.modules.hos.vo.DoctorVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.hos.entity.CollDoctorEntity;
import io.renren.modules.hos.service.CollDoctorService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author ryf
 * @email 2559228480@qq.com
 * @date 2021-12-12 20:01:07
 */
@RestController
@RequestMapping("hos/colldoctor")
public class CollDoctorController {
    @Autowired
    private CollDoctorService collDoctorService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("hos:colldoctor:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = collDoctorService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("hos:colldoctor:info")
    public R info(@PathVariable("id") Long id){
		CollDoctorEntity collDoctor = collDoctorService.getById(id);

        return R.ok().put("collDoctor", collDoctor);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("hos:colldoctor:save")
    public R save(@RequestBody CollDoctorEntity collDoctor){
		collDoctorService.save(collDoctor);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("hos:colldoctor:update")
    public R update(@RequestBody CollDoctorEntity collDoctor){
		collDoctorService.updateById(collDoctor);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("hos:colldoctor:delete")
    public R delete(@RequestBody Long[] ids){
		collDoctorService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询收藏医生的信息
     * @param doctorId
     * @return
     */
    @PostMapping("/collInfo/{id}")
    public R selectCollMedicineInfoById(@PathVariable("id") Long doctorId){
        DoctorVo doctorVo = collDoctorService.selectDoctorById(doctorId);
        return R.ok().put("doctorVo", doctorVo);
    }

    /**
     * 添加收藏
     */
    @PostMapping("/add/{id}")
    public R addCollDoctor(@PathVariable("id") Long doctorId){
        boolean flag = collDoctorService.addCollDoctor(doctorId);
        if (flag){
            return R.ok().put("data", "收藏成功");
        }else {
            return R.error().put("data", "收藏失败");
        }
    }

    /**
     *  取消收藏
     */
    @PostMapping("/cancel/{id}")
    public R cancelCollDoctor(@PathVariable("id") Long doctorId){
        boolean flag = collDoctorService.cancel(doctorId);
        if (flag){
            return R.ok().put("data", "取消收藏成功");
        }else {
            return R.error().put("data", "取消首次失败");
        }
    }

    /**
     * 查询某个用户收藏的医生
     */
    @RequestMapping("/userColl")
    public R selectUserColl(@RequestParam Map<String, Object> params){
        PageUtils page = collDoctorService.selectUserColl(params);

        return R.ok().put("page", page);
    }

}
